//
//  ShiLiTestResultViewController.m
//  安好
//
//  Created by qinlongqing on 14-8-27.
//  Copyright (c) 2014年 冯凯. All rights reserved.
//

#import "ShiLiTestResultViewController.h"
#import "ShiLiTestViewController.h"
#import "AppConfig.h"

@interface ShiLiTestResultViewController ()
{
    UIImage *_imageV;
    
    UIView *leftEyeView;
    UIView *leftEyePictureView;
    UIImageView *leftEyeImageViewCenter;
    
    UIView *rightEyeView;
    UIView *rightEyePictureView;
    UIImageView *rightEyeImageViewCenter;
    
    CGFloat eyeViewWidthAndHeight;
    CGFloat pingYuHeight;
    CGFloat dateAndSealViewHeight;
    CGFloat shareBTNHeight;
    CGFloat space;
}
@end

@implementation ShiLiTestResultViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationItem.title = @"测试报告";
    
    self.view.backgroundColor = UIColorFromRGB(0xe7f1f4);

    [self makeNavBar];
    
    if (kScreenWidth == 414) {
        eyeViewWidthAndHeight = 156;
        pingYuHeight = 24;
        dateAndSealViewHeight = 96;
        shareBTNHeight = 54;
    }
    else{
        eyeViewWidthAndHeight = 130;
        pingYuHeight = 20;
        dateAndSealViewHeight = 80;
        shareBTNHeight = 45;
    }
    space = (kScreenHeight - 64 - eyeViewWidthAndHeight - pingYuHeight - dateAndSealViewHeight - shareBTNHeight)/5;
    
#pragma 左眼
    [self createLeftEyeTestReportViewWithResult:[[self.testResultDict valueForKey:@"leftResult"] integerValue]];
#pragma 右眼
    [self createRightEyeTestReportViewWithResult:[[self.testResultDict valueForKey:@"rightResult"] integerValue]];
    
    //-------------------评语--------------------
    UILabel *pingYu = [[UILabel alloc]init];
    pingYu.frame = CGRectMake(0, leftEyeView.frame.origin.y + leftEyeView.frame.size.height + space, kScreenWidth, pingYuHeight);
    if (kScreenWidth == 414) {
        pingYu.font = [UIFont systemFontOfSize:17];
    }
    else{
        pingYu.font = [UIFont systemFontOfSize:15];
    }
    pingYu.backgroundColor = [UIColor clearColor];
    pingYu.textAlignment = NSTextAlignmentCenter;
    pingYu.textColor = [UIColor blackColor];
    [pingYu setAdjustsFontSizeToFitWidth:YES];
    pingYu.text = [self getPingYuWithLeftEye:[[self.testResultDict valueForKey:@"leftResult"] intValue] andRightEye:[[self.testResultDict valueForKey:@"rightResult"] intValue]];
    [self.view addSubview:pingYu];
    //---------------------时间和盖章----------------------
    UIView *dateAndSealView = [[UIView alloc]init];
    dateAndSealView.frame = CGRectMake(0, pingYu.frame.origin.y + pingYu.frame.size.height + space, kScreenWidth, dateAndSealViewHeight);
    [self.view addSubview:dateAndSealView];
    
    UILabel *dateLabel = [[UILabel alloc]init];
    if (kScreenWidth == 414) {
        dateLabel.frame = CGRectMake(kScreenWidth*(170.0/320.0), 50, 168, 36);
        dateLabel.font = [UIFont systemFontOfSize:15];
    }
    else{
        dateLabel.frame = CGRectMake(kScreenWidth*(170.0/320.0), 45, 140, 30);
        dateLabel.font = [UIFont systemFontOfSize:13];
    }
    dateLabel.backgroundColor = [UIColor clearColor];
    dateLabel.textAlignment = NSTextAlignmentCenter;
    dateLabel.textColor = [UIColor grayColor];
    
    NSDate *dates = [NSDate date];
    NSDateFormatter *formatter =  [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy年MM月dd日  HH:mm"];
    NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"Asia/beijing"];
    [formatter setTimeZone:timeZone];
    NSString *loctime = [formatter stringFromDate:dates];
    
    dateLabel.text = loctime;
    [dateAndSealView addSubview:dateLabel];
    
    UIImageView *sealView = [[UIImageView alloc]init];
    if (kScreenWidth == 414) {
        sealView.frame = CGRectMake(kScreenWidth*(233.0/320.0), 0, 80, 80);
    }
    else{
        sealView.frame = CGRectMake(kScreenWidth*(233.0/320.0), 0, 67, 67);
    }
    sealView.image = [UIImage imageNamed:@"ce_shi_bao_gao_seal"];
    [dateAndSealView addSubview:sealView];
    
    
    UIButton *shareBTN = [[UIButton alloc]init];
    shareBTN.layer.cornerRadius = 3;
    if (kScreenWidth == 414) {
        shareBTN.frame = CGRectMake(20, dateAndSealView.frame.origin.y + dateAndSealView.frame.size.height + space, kScreenWidth - 40, shareBTNHeight);
    }
    else{
        shareBTN.frame = CGRectMake(15, dateAndSealView.frame.origin.y + dateAndSealView.frame.size.height + space, kScreenWidth - 30, shareBTNHeight);
    }
    [shareBTN setBackgroundImage:[UIImage imageNamed:@"tiJianFenXiangBG"] forState:UIControlStateNormal];
    [shareBTN setBackgroundImage:[UIImage imageNamed:@"tiJianFenXiangBG"] forState:UIControlStateHighlighted];
    [shareBTN setTitle:@"分享" forState:UIControlStateNormal];
    [shareBTN setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [shareBTN setShowsTouchWhenHighlighted:NO];
    [shareBTN addTarget:self action:@selector(doToShare:) forControlEvents:UIControlEventTouchUpInside];
    if ([[UserManager shareInstance] getUserIsLogin].length > 0) {
        shareBTN.hidden = NO;
    }
    else{
        shareBTN.hidden = YES;
    }
    [self.view addSubview:shareBTN];

}

- (void)makeNavBar{
    UIBarButtonItem *backBtnImg = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"公用_返回.png"] style:UIBarButtonItemStylePlain target:self action:@selector(doBack)];
    [backBtnImg setTintColor:[UIColor whiteColor]];
    self.navigationItem.leftBarButtonItem = backBtnImg;
}

-(void)doBack{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)createLeftEyeTestReportViewWithResult:(NSInteger)leftResult{
    leftEyeView = [[UIView alloc]init];
    leftEyeView.frame = CGRectMake((kScreenWidth - eyeViewWidthAndHeight*2)/3, space, eyeViewWidthAndHeight, eyeViewWidthAndHeight);
    leftEyeView.backgroundColor = [UIColor clearColor];
    [self.view addSubview:leftEyeView];

    UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, leftEyeView.frame.size.width, leftEyeView.frame.size.height)];
    if (10<=leftResult && leftResult<=13) {//正常
        MyNSLog("左眼正常");
        imageView.image = [UIImage imageNamed:@"shi_li_youxiu"];
    }
    else if (leftResult>13) {//近视
        MyNSLog("左眼近视");
        imageView.image = [UIImage imageNamed:@"shi_li_jinshi"];
    }
    else if (leftResult<10) {//远视
        MyNSLog("左眼远视");
        imageView.image = [UIImage imageNamed:@"shi_li_yuanShi"];
    }
    [leftEyeView addSubview:imageView];
    
    UILabel *zuoYan = [[UILabel alloc]init];
    if (kScreenWidth == 414) {
        zuoYan.frame = CGRectMake((leftEyeView.frame.size.width - 24)/2, (leftEyeView.frame.size.width - 24)/2 - 12, 24, 24);
        zuoYan.font = [UIFont systemFontOfSize:18];
    }
    else{
        zuoYan.frame = CGRectMake((leftEyeView.frame.size.width - 20)/2, (leftEyeView.frame.size.width - 20)/2 - 12, 20, 20);
        zuoYan.font = [UIFont systemFontOfSize:16];
    }
    zuoYan.text = @"左";
    zuoYan.textAlignment = NSTextAlignmentCenter;
    zuoYan.textColor = [UIColor blackColor];
    zuoYan.backgroundColor = [UIColor clearColor];
    [leftEyeView addSubview:zuoYan];
    
    UILabel *shiLiNumber = [[UILabel alloc]initWithFrame:CGRectMake(45, 65, 40, 20)];
    if (kScreenWidth == 414) {
        shiLiNumber.frame = CGRectMake((leftEyeView.frame.size.width - 48)/2, (leftEyeView.frame.size.width)/2, 48, 24);
        shiLiNumber.font = [UIFont systemFontOfSize:21];
    }
    else{
        shiLiNumber.frame = CGRectMake((leftEyeView.frame.size.width - 40)/2, (leftEyeView.frame.size.width)/2, 40, 20);
        shiLiNumber.font = [UIFont systemFontOfSize:19];
    }
    shiLiNumber.text = [NSString stringWithFormat:@"%.1f",[AppConfig getShiLiLevelWithWordSize:[[self.testResultDict valueForKey:@"leftResult"] intValue]]];
    shiLiNumber.textAlignment = NSTextAlignmentCenter;
    shiLiNumber.textColor = UIColorFromRGB(0x4fc1e9);
    shiLiNumber.backgroundColor = [UIColor clearColor];
    [leftEyeView addSubview:shiLiNumber];

}


- (void)createRightEyeTestReportViewWithResult:(NSInteger)rightResult{
    rightEyeView = [[UIView alloc]init];
    rightEyeView.frame = CGRectMake((kScreenWidth - eyeViewWidthAndHeight*2)/3*2 + eyeViewWidthAndHeight, space, eyeViewWidthAndHeight, eyeViewWidthAndHeight);
    rightEyeView.backgroundColor = [UIColor clearColor];
    [self.view addSubview:rightEyeView];
    
    UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, rightEyeView.frame.size.width, rightEyeView.frame.size.height)];
    if (10<=rightResult && rightResult<=13) {//正常
        MyNSLog("左眼正常");
        imageView.image = [UIImage imageNamed:@"shi_li_youxiu"];
    }
    else if (rightResult>13) {//近视
        MyNSLog("左眼近视");
        imageView.image = [UIImage imageNamed:@"shi_li_jinshi"];
    }
    else if (rightResult<10) {//远视
        MyNSLog("左眼远视");
        imageView.image = [UIImage imageNamed:@"shi_li_yuanShi"];
    }
    [rightEyeView addSubview:imageView];
    
    UILabel *youYan = [[UILabel alloc]init];
    if (kScreenWidth == 414) {
        youYan.frame = CGRectMake((rightEyeView.frame.size.width - 24)/2, (rightEyeView.frame.size.width - 24)/2 - 12, 24, 24);
        youYan.font = [UIFont systemFontOfSize:18];
    }
    else{
        youYan.frame = CGRectMake((rightEyeView.frame.size.width - 20)/2, (rightEyeView.frame.size.width - 20)/2 - 12, 20, 20);
        youYan.font = [UIFont systemFontOfSize:16];
    }
    youYan.text = @"右";
    youYan.textAlignment = NSTextAlignmentCenter;
    youYan.textColor = [UIColor blackColor];
    youYan.backgroundColor = [UIColor clearColor];
    [rightEyeView addSubview:youYan];
    
    
    UILabel *shiLiNumber = [[UILabel alloc]init];
    if (kScreenWidth == 414) {
        shiLiNumber.frame = CGRectMake((rightEyeView.frame.size.width - 48)/2, (rightEyeView.frame.size.width)/2, 48, 24);
        shiLiNumber.font = [UIFont systemFontOfSize:21];
    }
    else{
        shiLiNumber.frame = CGRectMake((rightEyeView.frame.size.width - 40)/2, (rightEyeView.frame.size.width)/2, 40, 20);
        shiLiNumber.font = [UIFont systemFontOfSize:19];
    }
    shiLiNumber.text = [NSString stringWithFormat:@"%.1f",[AppConfig getShiLiLevelWithWordSize:[[self.testResultDict valueForKey:@"rightResult"] intValue]]];
    shiLiNumber.textAlignment = NSTextAlignmentCenter;
    shiLiNumber.textColor = UIColorFromRGB(0x4fc1e9);
    shiLiNumber.backgroundColor = [UIColor clearColor];
    [rightEyeView addSubview:shiLiNumber];

}

- (NSString *)getPingYuWithLeftEye:(int)leftEye andRightEye:(int)rightEye{
    if ((leftEye >= 10 && leftEye <= 13) && (rightEye >= 10 && rightEye <= 13)) {//左眼优秀，右眼优秀
        return @"您真的是火眼金睛啊！";
    }
    else if ((leftEye >= 10 && leftEye <= 13) && rightEye < 10){//左眼优秀，右眼远视
        return @"左眼优秀，右眼远视。";
    }
    else if ((leftEye >= 10 && leftEye <= 13) && rightEye > 13){//左眼优秀，右眼近视
        return @"左眼优秀，右眼近视。";
    }
    
    else if (leftEye < 10 && (rightEye >= 10 && rightEye <= 13)){//左眼远视，右眼优秀
        return @"左眼远视，右眼优秀。";
    }
    else if (leftEye < 10 && rightEye < 10){//左眼远视，右眼远视
        return @"您确定您不是千里眼？";
    }
    else if (leftEye < 10 && rightEye > 13){//左眼远视，右眼近视
        return @"您是怎么做到的？";
    }
    else if (leftEye > 13 && (rightEye >= 10 && rightEye <= 13)){//左眼近视，右眼优秀
        return @"左眼近视，右眼优秀。";
    }
    else if (leftEye > 13 && rightEye < 10){//左眼近视，右眼远视
        return @"您是怎么做到的？";
    }
    else if (leftEye > 13 && rightEye > 13){//左眼近视，右眼近视
        return @"保护视力，眼保健操走起吧！";
    }
    return nil;
}

- (void)doToShare:(UIButton *)sender{
    CGRect rect = CGRectMake(0, 0, kScreenWidth, sender.frame.origin.y);
//    if (IPHONE5_OR_LATER) {
//        rect = CGRectMake(0, 0, 320, 375);
//    }
//    else{
//        rect = CGRectMake(0, 0, 320, 325);
//    }
    
    [self imageFromView:self.view atFrame:rect];
#pragma 让分享的视图出现，并显示到屏幕的最前方
    [self showShareView];
}
#pragma 截图视图
- (void)imageFromView:(UIView *)theView atFrame:(CGRect)r
{
    UIGraphicsBeginImageContext(theView.frame.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    [theView.layer renderInContext:context];
    UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    CGImageRef imageRef = theImage.CGImage;
    CGImageRef subImageRef = CGImageCreateWithImageInRect(imageRef, r);//原图中抠出来部分图
    UIImage *subImage = [UIImage imageWithCGImage:subImageRef];//新图
    _imageV = subImage;
}

#pragma 实现share方法，通过点击的视图的tag值判断是什么类型的分享
- (void)share:(UITapGestureRecognizer *)shareTap{
    switch (shareTap.view.tag) {
        case 11:{//微信
            [self weixinShare:kWeiXinShareUrl :kWeiXinShareTitle :kWeiXinShareText :_imageV];
        }
            break;
        case 12:{//朋友圈
            [self weixinFriendShare:kWeiXinFriendShareUrl :kWeiXinFriendShareTitle :kWeiXinFriendShareText :_imageV];
        }
            break;
        case 13:{//短信
            [self showSMSPicker:kWeiXinFriendShareUrl :kWeiXinFriendShareTitle :kWeiXinFriendShareText :nil];
        }
            break;
        case 14:{//QQ
            [self qqShare:kQQshareUrl :kQQshareTitle :kQQshreDescription :_imageV];
        }
            break;
        case 15:{//QQ空间
            [self qqZoneShare:kQQZoneShareUrl :kQQZoneShareTitle :kQQZoneShareDescription :_imageV];
        }
            break;
        case 16:{//新浪微博
            [self sinaWeiboShare:kSinaWeiboShareUrl :kSinaWeiboShareTitle :kSinaWeiboShareText :_imageV];
        }
            break;

        default:
            break;
    }
}

//- (void)createLeftEyeTestReport{
//#pragma 底层图像view
//    UIView *leftEyeBottomPictureView = [[UIView alloc]init];
//    if (IPHONE5_OR_LATER) {
//        leftEyeBottomPictureView.frame = CGRectMake(15, 63, 130, 130);
//    }
//    else{
//        leftEyeBottomPictureView.frame = CGRectMake(15, 38, 130, 130);
//    }
//    leftEyeBottomPictureView.backgroundColor = [UIColor clearColor];
//    [self.view addSubview:leftEyeBottomPictureView];
//    
//    UIImageView *bgImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 130, 130)];
//    bgImageView.image = [UIImage imageNamed:@"ce_shi_bao_gao_buttonColor"];
//    [leftEyeBottomPictureView addSubview:bgImageView];
//#pragma 图像view
//    leftEyePictureView = [[UIView alloc]init];
//    if (IPHONE5_OR_LATER) {
//        leftEyePictureView.frame = CGRectMake(15, 63, 130, 130);
//    }
//    else{
//        leftEyePictureView.frame = CGRectMake(15, 38, 130, 130);
//    }
//    leftEyePictureView.backgroundColor = [UIColor clearColor];
//    [self.view addSubview:leftEyePictureView];
//    
//    UIImageView *leftEyeImageViewOther = [[UIImageView alloc]initWithFrame:CGRectMake(6, 0, 124, 130)];
//    leftEyeImageViewOther.image = [UIImage imageNamed:@"ce_shi_bao_gao_other"];
//    [leftEyePictureView addSubview:leftEyeImageViewOther];
//    
//    leftEyeImageViewCenter = [[UIImageView alloc]initWithFrame:CGRectMake(35, 33, 60, 64)];
//    leftEyeImageViewCenter.image = [UIImage imageNamed:@"ce_shi_bao_gao_center"];
//    [leftEyePictureView addSubview:leftEyeImageViewCenter];
//#pragma 字体View
//    UIView *leftEyeLabelView = [[UIView alloc]init];
//    if (IPHONE5_OR_LATER) {
//        leftEyeLabelView.frame = CGRectMake(15, 63, 130, 130);
//    }
//    else{
//        leftEyeLabelView.frame = CGRectMake(15, 38, 130, 130);
//    }
//    leftEyeLabelView.backgroundColor = [UIColor clearColor];
//    [self.view addSubview:leftEyeLabelView];
//    
//    UILabel *zuoYan = [[UILabel alloc]initWithFrame:CGRectMake(55, 43, 20, 20)];
//    zuoYan.text = @"左";
//    zuoYan.textAlignment = NSTextAlignmentCenter;
//    zuoYan.textColor = [UIColor blackColor];
//    zuoYan.font = [UIFont systemFontOfSize:16];
//    zuoYan.backgroundColor = [UIColor clearColor];
//    [leftEyeLabelView addSubview:zuoYan];
//    
//    UILabel *shiLiNumber = [[UILabel alloc]initWithFrame:CGRectMake(45, 67, 40, 20)];
//    shiLiNumber.text = [NSString stringWithFormat:@"%.1f",[AppConfig getShiLiLevelWithWordSize:[[self.testResultDict valueForKey:@"leftResult"] intValue]]];
//    shiLiNumber.textAlignment = NSTextAlignmentCenter;
//    shiLiNumber.textColor = UIColorFromRGB(0x4fc1e9);
//    shiLiNumber.font = [UIFont systemFontOfSize:19];
//    shiLiNumber.backgroundColor = [UIColor clearColor];
//    [leftEyeLabelView addSubview:shiLiNumber];
//    
//    UILabel *youXiu = [[UILabel alloc]initWithFrame:CGRectMake(50, 10, 30, 20)];
//    youXiu.text = @"优秀";
//    youXiu.textAlignment = NSTextAlignmentCenter;
//    youXiu.textColor = [UIColor whiteColor];
//    youXiu.font = [UIFont systemFontOfSize:12];
//    youXiu.backgroundColor = [UIColor clearColor];
//    [leftEyeLabelView addSubview:youXiu];
//    
//    UILabel *yuanShi = [[UILabel alloc]initWithFrame:CGRectMake(9, 78, 30, 20)];
//    yuanShi.text = @"远视";
//    yuanShi.textAlignment = NSTextAlignmentCenter;
//    yuanShi.textColor = [UIColor whiteColor];
//    yuanShi.font = [UIFont systemFontOfSize:12];
//    yuanShi.backgroundColor = [UIColor clearColor];
//    [leftEyeLabelView addSubview:yuanShi];
//    
//    UILabel *jinShi = [[UILabel alloc]initWithFrame:CGRectMake(91, 78, 30, 20)];
//    jinShi.text = @"近视";
//    jinShi.textAlignment = NSTextAlignmentCenter;
//    jinShi.textColor = [UIColor whiteColor];
//    jinShi.font = [UIFont systemFontOfSize:12];
//    jinShi.backgroundColor = [UIColor clearColor];
//    [leftEyeLabelView addSubview:jinShi];
//    
//}

//- (void)createRightEyeTestReport{
//#pragma 底层图像view
//    UIView *rightEyeBottomPictureView = [[UIView alloc]init];
//    if (IPHONE5_OR_LATER) {
//        rightEyeBottomPictureView.frame = CGRectMake(175, 63, 130, 130);
//    }
//    else{
//        rightEyeBottomPictureView.frame = CGRectMake(175, 38, 130, 130);
//    }
//    rightEyeBottomPictureView.backgroundColor = [UIColor clearColor];
//    [self.view addSubview:rightEyeBottomPictureView];
//    
//    UIImageView *bgImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 130, 130)];
//    bgImageView.image = [UIImage imageNamed:@"ce_shi_bao_gao_buttonColor"];
//    [rightEyeBottomPictureView addSubview:bgImageView];
//#pragma 图像view
//    rightEyePictureView = [[UIView alloc]init];
//    if (IPHONE5_OR_LATER) {
//        rightEyePictureView.frame = CGRectMake(175, 63, 130, 130);
//    }
//    else{
//        rightEyePictureView.frame = CGRectMake(175, 38, 130, 130);
//    }
//    rightEyePictureView.backgroundColor = [UIColor clearColor];
//    [self.view addSubview:rightEyePictureView];
//    
//    UIImageView *rightEyeImageViewOther = [[UIImageView alloc]initWithFrame:CGRectMake(6, 0, 124, 130)];
//    rightEyeImageViewOther.image = [UIImage imageNamed:@"ce_shi_bao_gao_other"];
//    [rightEyePictureView addSubview:rightEyeImageViewOther];
//    
//    rightEyeImageViewCenter = [[UIImageView alloc]initWithFrame:CGRectMake(35, 33, 60, 64)];
//    rightEyeImageViewCenter.image = [UIImage imageNamed:@"ce_shi_bao_gao_center"];
//    [rightEyePictureView addSubview:rightEyeImageViewCenter];
//#pragma 字体View
//    UIView *rightEyeLabelView = [[UIView alloc]init];
//    if (IPHONE5_OR_LATER) {
//        rightEyeLabelView.frame = CGRectMake(175, 63, 130, 130);
//    }
//    else{
//        rightEyeLabelView.frame = CGRectMake(175, 38, 130, 130);
//    }
//    rightEyeLabelView.backgroundColor = [UIColor clearColor];
//    [self.view addSubview:rightEyeLabelView];
//    
//    UILabel *zuoYan = [[UILabel alloc]initWithFrame:CGRectMake(55, 43, 20, 20)];
//    zuoYan.text = @"右";
//    zuoYan.textAlignment = NSTextAlignmentCenter;
//    zuoYan.textColor = [UIColor blackColor];
//    zuoYan.font = [UIFont systemFontOfSize:16];
//    zuoYan.backgroundColor = [UIColor clearColor];
//    [rightEyeLabelView addSubview:zuoYan];
//    
//    UILabel *shiLiNumber = [[UILabel alloc]initWithFrame:CGRectMake(45, 67, 40, 20)];
//    shiLiNumber.text = [NSString stringWithFormat:@"%.1f",[AppConfig getShiLiLevelWithWordSize:[[self.testResultDict valueForKey:@"rightResult"] intValue]]];
//    shiLiNumber.textAlignment = NSTextAlignmentCenter;
//    shiLiNumber.textColor = UIColorFromRGB(0x4fc1e9);
//    shiLiNumber.font = [UIFont systemFontOfSize:19];
//    shiLiNumber.backgroundColor = [UIColor clearColor];
//    [rightEyeLabelView addSubview:shiLiNumber];
//    
//    UILabel *youXiu = [[UILabel alloc]initWithFrame:CGRectMake(50, 10, 30, 20)];
//    youXiu.text = @"优秀";
//    youXiu.textAlignment = NSTextAlignmentCenter;
//    youXiu.textColor = [UIColor whiteColor];
//    youXiu.font = [UIFont systemFontOfSize:12];
//    youXiu.backgroundColor = [UIColor clearColor];
//    [rightEyeLabelView addSubview:youXiu];
//    
//    UILabel *yuanShi = [[UILabel alloc]initWithFrame:CGRectMake(9, 78, 30, 20)];
//    yuanShi.text = @"远视";
//    yuanShi.textAlignment = NSTextAlignmentCenter;
//    yuanShi.textColor = [UIColor whiteColor];
//    yuanShi.font = [UIFont systemFontOfSize:12];
//    yuanShi.backgroundColor = [UIColor clearColor];
//    [rightEyeLabelView addSubview:yuanShi];
//    
//    UILabel *jinShi = [[UILabel alloc]initWithFrame:CGRectMake(91, 78, 30, 20)];
//    jinShi.text = @"近视";
//    jinShi.textAlignment = NSTextAlignmentCenter;
//    jinShi.textColor = [UIColor whiteColor];
//    jinShi.font = [UIFont systemFontOfSize:12];
//    jinShi.backgroundColor = [UIColor clearColor];
//    [rightEyeLabelView addSubview:jinShi];
//    
//}

- (void)rotatingCompassWithLeftEye:(int)leftEye andRightEye:(int)rightEye{//旋转罗盘
    //正常：10<=x<=14
    //左眼
    MyNSLog("11111111111111 left=%d  right=%d",leftEye,rightEye);
    leftEyeImageViewCenter.layer.transform = CATransform3DMakeRotation(-(M_PI*2)/3, 0, 0, 1);
    if (10<=leftEye && leftEye<=13) {//正常
        MyNSLog("左眼正常");

        leftEyePictureView.layer.transform = CATransform3DMakeRotation((M_PI*2)/3, 0, 0, 1);
    }
    else if (leftEye>13) {//近视
        MyNSLog("左眼近视");

        leftEyePictureView.layer.transform = CATransform3DMakeRotation(-(M_PI*2)/3 + M_PI/180*3, 0, 0, 1);
    }
    else if (leftEye<10) {//远视
        MyNSLog("左眼远视");
    }
    //右眼
    rightEyeImageViewCenter.layer.transform = CATransform3DMakeRotation(-(M_PI*2)/3, 0, 0, 1);
    if (10<=rightEye && rightEye<=13) {//正常
        MyNSLog("右眼正常");

        rightEyePictureView.layer.transform = CATransform3DMakeRotation((M_PI*2)/3, 0, 0, 1);
    }
    else if (rightEye>13) {//近视
        MyNSLog("右眼近视");

        rightEyePictureView.layer.transform = CATransform3DMakeRotation(-(M_PI*2)/3 + M_PI/180*3, 0, 0, 1);
    }
    else if (rightEye<10) {//远视
        MyNSLog("右眼远视");

    }
}

- (void)deleteCode{
    /*
     UILabel *nameAndFenShuLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 86, 320, 30)];
     if (iPhone5) {
     CGRect rect = nameAndFenShuLabel.frame;
     rect.origin.y = rect.origin.y + 20;
     nameAndFenShuLabel.frame = rect;
     }
     nameAndFenShuLabel.textAlignment = NSTextAlignmentCenter;
     nameAndFenShuLabel.textColor = [UIColor blackColor];
     nameAndFenShuLabel.font = [UIFont systemFontOfSize:15];
     switch (self.testType) {
     case shiLiTest:{
     NSString *showStr = [NSString stringWithFormat:@"%@的左眼:%@  右眼:%@",[self.testResultDict valueForKey:@"testUserName"],[self.testResultDict valueForKey:@"leftResult"],[self.testResultDict valueForKey:@"rightResult"]];
     
     NSRange leftRange = [showStr rangeOfString:@"左眼:"];
     NSRange centerRange = [showStr rangeOfString:@"  "];
     NSRange rightRange = [showStr rangeOfString:@"右眼:"];
     
     NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:showStr];
     [attributedString addAttribute:NSForegroundColorAttributeName value:[self colorWithHexString:@"#4fc1e9"] range:NSMakeRange(leftRange.location + leftRange.length, centerRange.location - leftRange.location - leftRange.length)];
     [attributedString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:16] range:NSMakeRange(leftRange.location + leftRange.length, centerRange.location - leftRange.location - leftRange.length)];
     
     [attributedString addAttribute:NSForegroundColorAttributeName value:[self colorWithHexString:@"#4fc1e9"] range:NSMakeRange(rightRange.location + rightRange.length, showStr.length - rightRange.location - rightRange.length)];
     [attributedString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:16] range:NSMakeRange(rightRange.location + rightRange.length, showStr.length - rightRange.location - rightRange.length)];
     
     nameAndFenShuLabel.attributedText = attributedString;
     }
     break;
     case xinLvTest:
     nameAndFenShuLabel.text = [NSString stringWithFormat:@"%@的",[self.testResultDict valueForKey:@"testUserName"]];
     break;
     
     default:
     break;
     }
     nameAndFenShuLabel.adjustsFontSizeToFitWidth = YES;
     nameAndFenShuLabel.backgroundColor = [UIColor clearColor];
     [self.view addSubview:nameAndFenShuLabel];
     
     
     UIImageView *levelImageView = [[UIImageView alloc]initWithFrame:CGRectMake(75, 130, 170, 170)];
     if (iPhone5) {
     CGRect rect = levelImageView.frame;
     rect.origin.y = rect.origin.y + 30;
     levelImageView.frame = rect;
     }
     levelImageView.image = [UIImage imageNamed:@"ce_shi_bao_gao_level"];
     [self.view addSubview:levelImageView];
     
     
     switch (self.testType) {
     case shiLiTest:{
     //左眼
     UIImageView *positionImgeViewLeft = [[UIImageView alloc]init];
     positionImgeViewLeft.image = [UIImage imageNamed:@"ce_shi_bao_gao_position"];
     if ([self.testResultDict valueForKey:@"leftResult"]) {
     positionImgeViewLeft.frame = CGRectMake(185, 117, 50, 31);
     if (iPhone5) {
     CGRect rect = positionImgeViewLeft.frame;
     rect.origin.y = rect.origin.y + 30;
     positionImgeViewLeft.frame = rect;
     }
     }
     [self.view addSubview:positionImgeViewLeft];
     
     UILabel *positionTitleLeft = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 50, 24)];
     positionTitleLeft.backgroundColor = [UIColor clearColor];
     positionTitleLeft.textAlignment = NSTextAlignmentCenter;
     positionTitleLeft.textColor = [self colorWithHexString:@"#4fc1e9"];
     positionTitleLeft.font = [UIFont systemFontOfSize:13];
     positionTitleLeft.text = @"左眼";
     [positionImgeViewLeft addSubview:positionTitleLeft];
     
     //右眼
     UIImageView *positionImgeViewRight = [[UIImageView alloc]init];
     positionImgeViewRight.image = [UIImage imageNamed:@"ce_shi_bao_gao_position"];
     if ([self.testResultDict valueForKey:@"rightResult"]) {
     positionImgeViewRight.frame = CGRectMake(184, 131, 50, 31);
     if (iPhone5) {
     CGRect rect = positionImgeViewRight.frame;
     rect.origin.y = rect.origin.y + 30;
     positionImgeViewRight.frame = rect;
     }
     }
     positionImgeViewRight.layer.transform = CATransform3DMakeRotation(M_PI, 0, 0, 1);
     positionImgeViewRight.layer.anchorPoint = CGPointMake(0.5, 1);
     [self.view addSubview:positionImgeViewRight];
     
     UILabel *positionTitleRight = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 50, 24)];
     positionTitleRight.backgroundColor = [UIColor clearColor];
     positionTitleRight.textAlignment = NSTextAlignmentCenter;
     positionTitleRight.textColor = [self colorWithHexString:@"#4fc1e9"];
     positionTitleRight.font = [UIFont systemFontOfSize:13];
     positionTitleRight.text = @"右眼";
     positionTitleRight.layer.transform = CATransform3DMakeRotation(M_PI, 0, 0, 1);
     positionTitleRight.layer.anchorPoint = CGPointMake(0.5, 0.5);
     [positionImgeViewRight addSubview:positionTitleRight];
     }
     break;
     case xinLvTest:{
     //            UIImageView *positionImgeView = [[UIImageView alloc]initWithFrame:CGRectMake(185, 117, 50, 31)];
     //            positionImgeView.image = [UIImage imageNamed:@"ce_shi_bao_gao_position"];
     //            [self.view addSubview:positionImgeView];
     //
     //            UILabel *positionTitle = [[UILabel alloc]initWithFrame:CGRectMake(5, 5, 40, 21)];
     //            positionTitle.backgroundColor = [UIColor clearColor];
     //            positionTitle.textAlignment = NSTextAlignmentCenter;
     //            positionTitle.textColor = [self colorWithHexString:@"#4fc1e9"];
     //            positionTitle.font = [UIFont systemFontOfSize:13];
     //            positionTitle.text = @"你在这";
     //            [positionImgeView addSubview:positionTitle];
     }
     break;
     
     default:
     break;
     }
     
     UILabel *pingYuLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 310, 320, 40)];
     if (iPhone5) {
     CGRect rect = pingYuLabel.frame;
     rect.origin.y = rect.origin.y + 40;
     pingYuLabel.frame = rect;
     }
     pingYuLabel.backgroundColor = [UIColor clearColor];
     pingYuLabel.textAlignment = NSTextAlignmentCenter;
     pingYuLabel.textColor = [UIColor blackColor];
     pingYuLabel.font = [UIFont systemFontOfSize:15];
     pingYuLabel.text = @"你就是个神!";
     [self.view addSubview:pingYuLabel];
     
     UILabel *dateLabel = [[UILabel alloc]initWithFrame:CGRectMake(170, 350, 140, 30)];
     if (iPhone5) {
     CGRect rect = dateLabel.frame;
     rect.origin.y = rect.origin.y + 45;
     dateLabel.frame = rect;
     }
     dateLabel.backgroundColor = [UIColor clearColor];
     dateLabel.textAlignment = NSTextAlignmentCenter;
     dateLabel.textColor = [UIColor grayColor];
     dateLabel.font = [UIFont systemFontOfSize:13];
     
     NSDate *dates = [NSDate date];
     NSDateFormatter *formatter =  [[NSDateFormatter alloc] init];
     [formatter setDateFormat:@"yyyy年MM月dd日  HH:mm"];
     NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"Asia/beijing"];
     [formatter setTimeZone:timeZone];
     NSString *loctime = [formatter stringFromDate:dates];
     
     dateLabel.text = loctime;
     [self.view addSubview:dateLabel];
     
     
     UIImageView *sealView = [[UIImageView alloc]initWithFrame:CGRectMake(233, 300, 67, 67)];
     if (iPhone5) {
     CGRect rect = sealView.frame;
     rect.origin.y = rect.origin.y + 45;
     sealView.frame = rect;
     }
     sealView.image = [UIImage imageNamed:@"ce_shi_bao_gao_seal"];
     [self.view addSubview:sealView];
     
     
     UIButton *shareBTN = [[UIButton alloc]initWithFrame:CGRectMake(20, 420, 280, 35)];
     if (iPhone5) {
     CGRect rect = shareBTN.frame;
     rect.origin.y = rect.origin.y + 50;
     shareBTN.frame = rect;
     }
     [shareBTN setBackgroundImage:[UIImage imageNamed:@"按钮"] forState:UIControlStateNormal];
     [shareBTN setTitle:@"分享" forState:UIControlStateNormal];
     [shareBTN setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
     [shareBTN addTarget:self action:@selector(doToShare) forControlEvents:UIControlEventTouchUpInside];
     [self.view addSubview:shareBTN];
     
     */
 
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
